package com.itheima.hello.多线程;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class test1 {
    public static void main(String[] args) throws  Exception {
        //有100份礼物，小红，小明两人同时发送，当剩下的礼品小于10的时候则不发送，利用多线程模拟该过程并将线程的名称打印出来，
        //并最后在控制台打印出小红和小明各自送出的礼品数量
        List<String> gift = new ArrayList<>();
        Random r = new Random();
        String[] names = {"口红", "手表", "鲜花", "剃须刀", "皮带"};
        for (int i = 0; i < 100; i++) {
            gift.add(names[r.nextInt(names.length)] + (i+1));
        }
//        System.out.println(gift);
        //创建来两个线程代表小红和小明发送礼物
        sendThread xm = new sendThread(gift, "小明");
        xm.start();
        sendThread xh = new sendThread(gift, "小红");
        xh.start();

        xm.join();

        xh.join();

        System.out.println("小明发送了:" + xm.getCount() + "个礼物");
        System.out.println("小红发送了:" + xh.getCount() + "个礼物");


    }
}
